# _*_ coding : utf-8 _*_
# @Time : 2023/3/15 0015 15:46
# @Author : 菜鸟王小二
# @File : 12_urllib_异常
# @Project : python爬虫

import urllib.request
import urllib.error

# url = 'https://blog.csdn.net/m0_68111267/article/details/129038108'
url = 'https://www.ttt111.com'

headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36 Edg/110.0.1587.63'
}

try:
    request = urllib.request.Request(url=url, headers=headers)
    response = urllib.request.urlopen(request)
    content = response.read().decode('utf-8')
    print(content)
except urllib.error.HTTPError:
    print('系统正在升级!')
except urllib.error.URLError:
    print('抱歉，访问错误！')
